

************************************************************************************************************
****** DATA AND ANALYSIS MAIN DO FILE FOR COAL BANK FINANCE PROJECT
************************************************************************************************************

*Install white board package
ssc install schemepack

*************************************************************
*************************************************************
************ CODE INVOLVED WITH NO COMMERICAL DATA 
*************************************************************
*************************************************************

**************************************************************************
******* CLEAN GCEL
**************************************************************************
include "../Data_Cleaning/Clean_GCEL.do"

**************************************************************************
******* CLEAN Co2 INTENSITY (Our world in Data NGO)
**************************************************************************
include "../Data_Cleaning/Clean_Power_Co2_Intensity.do"

**************************************************************************
******* CLEAN SBTI
**************************************************************************
include "../Data_Cleaning/Clean_SBTI.do"

**************************************************************************
******* CLEAN RECLAIM FINANCE 
**************************************************************************
include "../Data_Cleaning/Clean_Reclaim_Finance_Score.do"

**************************************************************************
******* CLEAN GEM PLANTS
**************************************************************************
include "../Data_Cleaning/Clean_Gem_Plant_Data.do"

**************************************************************************
******* CLEAN IPCC SCENARIOS
**************************************************************************
include "../Data_Cleaning/Clean_Ipcc_Scenarios.do"

**************************************************************************
******* BUILD COAL EXIT DIVESTMENT SCORES 
**************************************************************************
*Generate simulation based measures of bank divestment policy strength
include "../Data_Cleaning/Build_Policy_Strength.do" 

**************************************************************************
******* BUILD COAL PLANT PLANNING DATA
**************************************************************************
//These samples come from the EIA Coal Generator Data and Beyond Coal Europe
include "../Data_Cleaning/Build_EIA_Generator.do" //USA
include "../Data_Cleaning/Build_EU_Generator.do" //EU

*************************************************************
*************************************************************
************ CODE INVOLVED WITH COMMERICAL DATA 
*************************************************************
*************************************************************

//Psedo-Data generated here and below! See Do file for detail

*************************************************************
************ PREPARE BORROWER FILE
*************************************************************
//This comes up with the sample of borrowers and links the borrowers
//to the underlying dealscan and IJ global datasets

include "../Data_Cleaning/Build_Borrower_File.do" 


*************************************************************
************ PREPARE TRANSACTION FILE
*************************************************************

//1. build transaction file
//		this is at the lender of transaction_id X borrower_id

//2. build lender file linked to transaction file
//		definition of lead bank is in below file
// 		this is at the level of transaction_id X lender_id

//Psedo-Data used for both of these files
include "../Data_Cleaning/Build_Transaction_File_Loans.do"
include "../Data_Cleaning/Build_Transaction_File_Bonds.do" 

//combine these into an overall transaction files set
include "../Data_Cleaning/Build_Transaction_Files.do" 



**************************************************************************
******* BUILD DERIVATIVE DATA POTENTIALLY BASED ON SAMPLE ITSELF
**************************************************************************
include "../Data_Cleaning/Build_Borrower_Characterstics.do"


*************************************************************
************ PRE-ANALYSIS DATA PROCESSING
*************************************************************
* Generate Exposure Shares 
include "../Data_Cleaning/Build_Borrow_Exposure.do" 

* Combine Into Shift Shares
include "../Data_Cleaning/Build_Shift_Share.do" 

* Build Non-Bank List
include "../Data_Cleaning/Build_Non_Bank_List.do" 

** GENERATE BORROWING PANEL AT BORROWER YEAR LEVEL 
include "../Data_Cleaning/Build_Borrowing_Panel.do"

** GENERATE EQUITY ISSUANCE PANEL AT BORROWER YEAR LEVEL 
include "../Data_Cleaning/Build_Equity_Issuance_Panel.do"

** GENERATE ANALYSIS DATASET THAT RUNS REGRESSIONS
include "../Data_Cleaning/Build_Panel_Firm_Year.do" 

** GENERATE PLANT LEVEL PANEL  
include "../Data_Cleaning/Build_Plant_Year_Panel.do" 

** GENERATE PLANT EMISSIONS DATA
include "../Data_Cleaning/Build_Plant_Emissions.do" 

** BUILD BANK LEVEL COAL PORTFOLIOS DATA
include "../Data_Cleaning/Build_Bank_Lending_Panel.do"

** BUILD BORROWER PRETRENDS
include "../Data_Cleaning/Build_Borrow_Pretrends.do"

** BUILD BANK PRETRENDS
include "../Data_Cleaning/Build_Bank_Pretrends.do"

*************************************************************
************ PRODUCE MAIN TABLES AND FIGURES
*************************************************************

//This file produces all main tables in the paper
include "../Data_Cleaning/Analysis_Policy_Determinants.do" //Prepare Table 3
include "../Data_Cleaning/Analysis_Bank_Financing.do" //Prepare Table 4
include "../Data_Cleaning/Analysis_Supply_Chain_Effects.do" //Prepare Table 5
//Table 6-8 needs Build_Panel_Firm_Year, which is in build files
//Table 9 Panel A needed Build_Planet_Year_Panel, which is in build files
include Main_Tables.do

//This file produces all main figures in the paper
include "../Data_Cleaning/Analysis_Number_Banks.do" //Prepare Figure 1
include "../Data_Cleaning/Analysis_Bank_Exit_Policies_By_Type.do" //Prepare Figure 3
include "../Data_Cleaning/Analysis_Loan_Issuance_By_Exit_Policy.do" //Prepare Figure 5
include "../Data_Cleaning/Analysis_Loan_Issuance_by_Borrower.do" //Prepare Figure 6
include "../Data_Cleaning/Analysis_Cumulative_Effects_on_Debt.do" //Prepare Figure 7
include "../Data_Cleaning/Analysis_Counterfactual_Simulation.do" //Prepare Figure 8 
include Main_Figures.do


